package org.achievement.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.achievement.system.common.RequestResult;
import org.achievement.system.dao.UserDao;
import org.achievement.system.pojo.entity.User;
import org.achievement.system.pojo.form.UserForm;
import org.achievement.system.service.UserService;

import org.achievement.system.pojo.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public RequestResult list(UserForm userForm) {
        if (userForm != null) {
            if (userForm.getPageSize() == null || userForm.getPageSize() <= 0) {
                userForm.setPageSize(10);
            }
            int offset = (userForm.getPage() - 1) * userForm.getPageSize();
            userForm.setOffset(offset);
        }
        List<UserVo> list = userDao.list(userForm);
        Integer totalSize = userDao.count(userForm);
        HashMap<String, Object> resultData = new HashMap<>();
        resultData.put("list", list);
        resultData.put("totalSize", totalSize);
        return RequestResult.success(resultData);
    }
}